package com.wjc.myktapplication.cusview

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import com.wjc.common.dp
import com.wjc.basemodule.utils.LogTools

/**
 * ClassName: com.wjc.myktapplication.cusview
 * Description:
 * JcChen on 2021.09.02.08:12
 */
class ColorTextView(context: Context, attributeSet: AttributeSet) :
    AppCompatTextView(context, attributeSet) {
    val TAG = "ColorTextView"

    private val ROUND_RADIUS = 4f.dp
    private val PADDING = 10f.dp
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val colors = arrayOf(Color.RED, Color.BLUE, Color.GRAY, Color.GREEN)
    private val textSizes = arrayOf(16,21,10,20)

    init {
        setTextColor(Color.BLACK)
        paint.color = colors[(0..3).random()]
        textSize = textSizes[(0..3).random()].toFloat()
    }

    override fun onDraw(canvas: Canvas) {
//        LogTools.d(TAG, "TagLayout --> width=$width,height=$height ");
        canvas.drawRoundRect(
            0f,
            0f,
            width.toFloat(),
            height.toFloat(),
            ROUND_RADIUS,
            ROUND_RADIUS,
            paint
        )
        super.onDraw(canvas)
    }
}